<?php


namespace app\api\controller;


use app\api\service\UserAmountService;
use app\api\service\LoginService;
use app\BaseController;
use app\Response;
use think\facade\Request;

class UserAmount extends BaseController
{
    /*** 我的钱包
     * @return json
    */
    public function mineWallet(){
        if(Request::isPost()) {
            $user_id = LoginService::getUserIdFromToken();
            if (!is_numeric($user_id)) {
                return $user_id;
            }
            $data = UserAmountService::mineWalletService($user_id);
            return $data;
        }
    }


    /*** 余额/稿费明细
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function userDetailed(){
        if (Request::isPost()) {
            $user_id = LoginService::getUserIdFromToken();
            if (!is_numeric($user_id)) {
                return $user_id;
            }
            $data = $this->request->post();
            try{
                $this->validate($data, 'UserDetailed');
            }catch (\Exception $e){
                return json(['code' => 0, 'msg' => lang($e->getMessage()), 'data' => [], 'count' => '']);
            }
            if(empty($data['page'])){
                $data['page'] = 1;
            }
            if(empty($data['num'])){
                $data['num'] = 10;
            }
            $result = UserAmountService::userDetailedService($user_id,$data);
            return $result;
        }
    }


    /*** 修改/设置支付密码
     * @return json
     */
    public function editPayPassWord(){
        if(Request::isPost()) {
            $user_id = LoginService::getUserIdFromToken();
            if (!is_numeric($user_id)) {
                return $user_id;
            }
            $data = $this->request->post();
            try{
                $this->validate($data, 'UserEditPayPassword');
            }catch (\Exception $e){
                return Response::wrapError($e->getMessage());
            }
            $res = UserAmountService::editPayPassWordService($user_id,$data);
            return $res;
        }
    }


    public function nextUserOrderList(){
        if(Request::isPost()) {
            $user_id = LoginService::getUserIdFromToken();
            if (!is_numeric($user_id)) {
                return $user_id;
            }
            $page = Request::param("page",1);
            $num = Request::param("num",10);
            $type = Request::param("type",1);//1未分成 2已分成 3全部
            $res = UserAmountService::nextUserOrderListService($user_id,$page,$num,$type);
            return $res;
        }
    }





}